package com.zyh.scs.common.core.exception;


import com.zyh.scs.common.core.util.R;

/**
 * 统一异常
 *
 * @author hezhao
 * @create 2019-03-12
 */
public class OpenException extends RuntimeException {
	private static final long serialVersionUID = -3008701086164361883L;

	private final int responseCode;

	private final String massage;

	public OpenException(OpenResponseCode responseCode, String message, Throwable cause) {
		super(message, cause);
		this.massage = message;
		this.responseCode = responseCode.getCode();
	}

	public OpenException(OpenResponseCode responseCode, Throwable cause) {
		super(cause);
		this.massage = responseCode.getDescription();
		this.responseCode = responseCode.getCode();
	}

	public OpenException(OpenResponseCode responseCode) {
		super(responseCode.getDescription());
		this.massage = responseCode.getDescription();
		this.responseCode = responseCode.getCode();
	}

	public OpenException(OpenResponseCode responseCode, String message) {
		super(message);
		this.responseCode = responseCode.getCode();
		this.massage = message;
	}

	public OpenException(String message) {
		super(message);
		this.responseCode = OpenResponseCode.BLANK.getCode();
		this.massage = message;
	}

	public OpenException(int responseCode, String message) {
		super(message);
		this.responseCode = responseCode;
		this.massage = message;
	}

	public OpenException() {
		super();
		this.responseCode = OpenResponseCode.FAILED.getCode();
		this.massage = OpenResponseCode.FAILED.getDescription();
	}

	public OpenException(String message, Throwable cause) {
		super(message, cause);
		this.responseCode = OpenResponseCode.FAILED.getCode();
		this.massage = message;
	}

	public OpenException(Exception e) {
		super(e.getMessage(), e);
		this.responseCode = OpenResponseCode.FAILED.getCode();
		this.massage = e.getMessage();
	}

	public int getResponseCode() {
		return this.responseCode;
	}

	public R<Object> getR() {
		if (0 == this.responseCode) {
			return R.failed();
		}
		R r = new R();
		r.setCode(this.responseCode);
		r.setMsg(this.massage);
		return r;
	}
}
																														
